package rent.hj.videoplayer.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.hg.library.config.FParser;

import java.io.File;

import rent.hj.videoplayer.service.UpdateService;

/**
 * Created by wangjianqiang on 2017/12/19 15:19.
 * Package name rent.hj.videoplayer.receiver
 */

public class UsbInReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String path = intent.getData().getPath();
        try {
            File file = new File(path);
            File[] files = file.listFiles();
            if (files != null && files.length > 0) {
                File[] folders = files[0].listFiles();
                for (int i = 0; i < folders.length; i++) {
                    String name = folders[i].getName();
                    if (name.equals(FParser.VIDEO_FOLDER_NAME)) {
                        Intent intent1 = new Intent(context, UpdateService.class);
                        intent1.putExtra("usbpath", files[0].getPath());
                        context.startService(intent1);
                        break;
                    }
                }
            }
        } catch (Exception e) {

        }
    }
}
